/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utn.tsb.tej.comunications;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.trolltech.qt.gui.QPixmap;
import java.io.Serializable;
import csm.uttils.Archive;

/**
 *
 * @author Carlos S. Moreno <CarlosS.Moreno@gmail.com>
 */
public class Preferences implements Serializable {

    private static String nickname, roomPassword;
    private static int port;
    private static int avatar;
    private static boolean pass;

    public static boolean isPass() {
        return pass;
    }

    public static void setPass(boolean pass) {
        Preferences.pass = pass;
    }

    /**
     * @return the nickname
     */
    public static String getNickname() {
        return nickname;
    }

    /**
     * @param aNickname the nickname to set
     */
    public static void setNickname(String aNickname) {
        nickname = aNickname;
    }

    /**
     * @return the roomPassword
     */
    public static String getRoomPassword() {
        return roomPassword;
    }

    /**
     * @param aRoomPassword the roomPassword to set
     */
    public static void setRoomPassword(String aRoomPassword) {
        roomPassword = aRoomPassword;
    }

    /**
     * @return the port
     */
    public static int getPort() {
        return port;
    }

    /**
     * @param aPort the port to set
     */
    public static void setPort(int aPort) {
        port = aPort;
    }

    /**
     * @return the avatar
     */
    public static int getAvatar() {
        return avatar;
    }

    /**
     * @param aAvatar the avatar to set
     */
    public static void setAvatar(int aAvatar) {
        avatar = aAvatar;
    }

    public static void loadPreferencesFromFile(String path) {
        String json="";
        try {
            json = new Archive(path).readString();
        } catch (Exception e) {
            return;
        }
        PreferencesDummie p = (new Gson().fromJson(json, PreferencesDummie.class));
        Preferences.avatar = p.avatar;
        Preferences.nickname = p.nickname;
        Preferences.port = p.port;
        Preferences.roomPassword = p.roomPassword;
        Preferences.setPass(p.pass);
    }

    public static boolean savePreferencesToFile(String path) {
        Gson gson = new Gson();
        PreferencesDummie p = new PreferencesDummie();
        System.out.println(p);
        String json = gson.toJson(p);
        return ((new Archive(path)).writeString(json, false));
    }

    public String toString(){
        return nickname + " " +
                roomPassword + " " +
                port + " "  ;

    }
}
